<?php
 class novelController extends UserController
 {
     public function init()
     {
         parent::init();
         if ($this->userinfo['author'] != 1) {
             $this->error('您尚未申请作者或者作者申请尚未通过审核');
         }
         $this->assign('userpagesign', 'author');
     }
     public function indexAction()
     {
         $zym_12 = $this->input->get('id');
         $this->assign('info', $this->model('novelsearch_info')->getinfo($zym_12));
         $this->display('novel');
     }
     public function addAction()
     {
         if ($this->request->isPost()) {
             $zym_8 = novel::nameformat($this->input->post('name', 'str', ''));
             $zym_10 = $this->model('author')->getinfo($this->userinfo['id']);
             $zym_7 = [ 'name' => $zym_8, 'author' => $zym_10['name'], 'category_id' => $this->input->post('category_id', 'int', $this->config->get('collect_category_default')), 'intro' => novel::introformat($this->input->post('intro', 'str', '')), 'siteid' => 0, ];
             if (isset($_FILES['cover'])) {
                 $zym_5 = new upload();
                 $zym_11 = array_shift($_FILES);
                 C('storage_path', C('upload_path', null, 'uploads/cover'));
                 $zym_5->setFile($zym_11);
                 $zym_9 = $zym_5->uploadone();
                 if ($zym_9['status'] == 1) {
                     $zym_7['cover'] = $zym_9['info']['fileurl'];
                 }
             }
             if ($zym_6 = $this->model('novelsearch_info')->add($zym_7)) {
                 $this->success('添加作品成功', U('author.novel.index', ['id' => $zym_6]));
             } else {
                 $this->error('添加失败');
             }
         }
         $this->assign('userpagesign', 'noveladd');
         $this->display('noveladd');
     }
     public function editAction()
     {
         $zym_12 = $this->input->get('id');
         if ($this->request->isPost()) {
             $zym_7 = [ 'id' => $zym_12, 'category_id' => $this->input->post('category_id', 'int', $this->config->get('collect_category_default')), 'intro' => novel::introformat($this->input->post('intro', 'str', '')), ];
             if (isset($_FILES['cover'])) {
                 $zym_5 = new upload();
                 $zym_11 = array_shift($_FILES);
                 C('storage_path', C('upload_path', null, 'uploads/cover'));
                 $zym_5->setFile($zym_11);
                 $zym_9 = $zym_5->uploadone();
                 if ($zym_9['status'] == 1) {
                     $zym_7['cover'] = $zym_9['info']['fileurl'];
                 }
             }
             if ($zym_6 = $this->model('novelsearch_info')->edit($zym_7)) {
                 $this->success('修改作品成功', U('author.novel.index', ['id' => $zym_6]));
             } else {
                 $this->error('修改失败');
             }
         }
         $this->assign('info', $this->model('novelsearch_info')->getinfo($zym_12));
         $this->assign('userpagesign', 'author');
         $this->display('noveledit');
     }
 }
